package com.zsc.wxm.ysh.anjo.result;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.util.HashMap;
import java.util.Map;

/**
 * @author playmaker
 * @since 2021-01-19
 */
@Data
@ApiModel(value = "全局统一返回结果")
public class Result {

    @ApiModelProperty(value = "是否成功")
    private Boolean success;

    @ApiModelProperty(value = "状态码")
    private Integer code;

    @ApiModelProperty(value = "返回的消息")
    private String message;

    @ApiModelProperty(value = "返回的数据")
    private Map<String,Object> data = new HashMap<>();

    public static Result error(String message){
        Result r = new Result();
        r.code = CodeEnum.ERROR.getCode();
        r.message = message;
        r.success = CodeEnum.ERROR.getSuccess();
        return r;
    }

    public static Result ok(String message){
        Result r = new Result();
        r.code = CodeEnum.SUCCESS.getCode();
        r.success = CodeEnum.SUCCESS.getSuccess();
        r.message = message;
        return r;
    }

    public static Result ok(String message,Map<String,Object> data){
        Result r = new Result();
        r.code = CodeEnum.SUCCESS.getCode();
        r.success = CodeEnum.SUCCESS.getSuccess();
        r.message = message;
        r.data = data;
        return r;
    }

    public static Result error(String message, Map<String, Object> data){
        Result r = new Result();
        r.code = CodeEnum.ERROR.getCode();
        r.message = message;
        r.success = CodeEnum.ERROR.getSuccess();
        r.data = data;
        return r;
    }

    public static Result error(CodeEnum codeEnum) {
        Result r = new Result();
        r.code = codeEnum.getCode();
        r.success = codeEnum.getSuccess();
        r.message = codeEnum.getMessage();
        return r;
    }

}
